package com.awei.study.regexp;

import org.junit.jupiter.api.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class regexp {

    @Test
    public void Test1() {
        String content = "2023年“五一”假期正式收官，根据文旅部披露的数据，文旅消费火热，国内旅游人次和国内旅" +
                "游收入全面超过疫情前同期。经文化和旅游部数据中心测算，全国国内旅游出游合计2.74亿人次，同比" +
                "增长70.83%，按可比口径恢复至2019年同期的119.09%；实现国内旅游收入1480.56亿元，同比增" +
                "长128.90%，按可比口径恢复至2019年同期的100.66%。";

        String regexp = "\\d\\d\\d\\d";

        Pattern pattern = Pattern.compile(regexp);

        Matcher matcher  = pattern.matcher(content);

        while (matcher.find()) {
            System.out.println("find: " + matcher.group(0));
        }
    }

    @Test
    public void Test2() {
        String content = "abcAbc";
        //元字符   选择匹配  限定符 {} *(0-n) ?(0,1) +(1-n)   分
//        String regexp = "[a-z]";
//        String regexp = "abc"; //区分大小写
//        String regexp = "(?i)abc"; //(?i)不区分大小写
//        String regexp = "a(?i)bc"; //bc不区分大小写
        String regexp = "a((?i)b)c"; //b不区分大小写

//        Pattern pattern = Pattern.compile(regexp,Pattern.CASE_INSENSITIVE);//Pattern.CASE_INSENSITIVE不区分大小写
        Pattern pattern = Pattern.compile(regexp);

        Matcher matcher  = pattern.matcher(content);


        while (matcher.find()) {
            System.out.println("find: " + matcher.group(0));
        }
    }

    @Test
    public void Test3() {
        String content = "123";
        //元字符 分组
        String regexp = "(\\d\\d)(\\d)"; //
//        String regexp = "(?:\\d\\d)\\d"; //
//        String regexp = "(?!\\d\\d)\\d"; //
//        String regexp = "(?=\\d\\d)\\d"; //

//        Pattern pattern = Pattern.compile(regexp,Pattern.CASE_INSENSITIVE);//Pattern.CASE_INSENSITIVE不区分大小写
        Pattern pattern = Pattern.compile(regexp);

        Matcher matcher  = pattern.matcher(content);


        while (matcher.find()) {
            System.out.println("find: " + matcher.group(0));
            System.out.println("find: " + matcher.group(1));
            System.out.println("find: " + matcher.group(2));
        }
    }

    @Test
    public void Test4() {
        //汉字
//        String content = "舞蹈我看";
//        String regexp = "^[\u0391-\uffe5]+$"; //
        //邮政编码
//        String content = "0123456";
//        String regexp = "^[1-9]\\d{5}$";
        //qq号
//        String content = "0123456";
//        String regexp = "^[1-9]\\d{4,10}$";
        //手机号码
//        String content = "0123456";
//        String regexp = "^1[3|4|5|8]\\d{9}$";
        //url
        String content = "https://blog.csdn.net/weixin_72052233/article/details/129470721";
        String regexp = "^((http|https)://)?([\\w-]+\\.)+([\\w-]+)(\\/[\\w%_/=?#&.-]*)?$";

        Pattern pattern = Pattern.compile(regexp);

        System.out.println(Pattern.matches(regexp,content));
        Matcher matcher  = pattern.matcher(content);
        if(matcher.find()) {
            System.out.println("符合");
        }else {
            System.out.println("不符合");
        }
    }
}
